<?php

    /*
    * Request get list video in HaiHuocTheThao application
    * Author   ThanhTV
    * Email    tranthanhepu@gmail.com
    * date     Mar 06, 2013
    */

    define("index", true);
    error_reporting(1);
    
    
    /* Include file */
    include "conf/config.php";   
    include "db/mysql.php";	
    /*End include file*/    

    $db = new database();
    $db -> db = array('host'=>$config['dbhost'], 'user'=>$config['dbuser'], 'pass'=>$config['dbpass'], 'db'=>$config['dbname']);
    $db -> connect();
    $db -> query("set names utf8");

    if (isset($_GET["page"])) { 
        $page  = $_GET["page"];         
    } 
    else { 
        $page=1;         
    };
    
    $start_from = ($page-1) * 20; 
    $sql = "SELECT * FROM list_videos ORDER BY date_create DESC LIMIT $start_from, 20"; 
    $rs = $db->query($sql);
    $result = $db->fetch_all($rs);

    foreach($result as $k => $v)
    {
        $arr_result[] = array(
            'id'            => $v['id'],
            'title'         => $v['title'],
            'description'   => $v['description'],
            'thumb'         => $v['thumb'],
            'url'           => $v['url'],
            'type'          => $v['type'],
            'read_count'    => $v['read_count'],            
            'date_create'   => $v['date_create']
        );
    }

    $jsonp_callback = $_GET['jsonp_callback_listvideos'];        
    echo $jsonp_callback . '('.json_encode($arr_result).');';    
    
?>